package com.kay.controller;

import com.kay.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Author: Kay
 * @CreateDate: 2021/9/17$ 21:14$
 * @UpdateUser: Kay
 * @UpdateDate: 2021/9/17$ 21:14$
 */
@RestController
@RequestMapping("/code")
public class CodeController {

    @Autowired
    private CodeService codeService;

    /**
     * ⽣成验证码并发送到对应邮箱
     * @param email
     * @return 成功true，失败 false
     */
    @GetMapping("/create/{email}")
    public boolean create(@PathVariable("email") String email){
        return codeService.createCodeAndSendEmail(email);
    }

    /**
     * 校验验证码是否正确
     * @param email
     * @param code
     * @return 0正确 1错误 2超时
     */
    @GetMapping("/validate/{email}/{code}")
    public Integer validate(@PathVariable("email") String email, @PathVariable("code") String code){
        return codeService.validateCodeAndEmail(email, code);
    }
}
